package com.saycode.back.articleType.controller;


import com.saycode.back.article.service.ArticleService;
import com.saycode.back.articleType.service.ContentTypeService;
import com.saycode.common.Constant;
import com.saycode.common.MethodUtil;
import com.saycode.common.beans.Article;
import com.saycode.common.beans.ContentType;
import com.saycode.common.beans.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * Created by zhangyanhui on 2017/6/14.
 */
@Controller("back/contentType")
@RequestMapping("back/contentType")
public class ContentTypeController {
    Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    @Qualifier("back/contentTypeService")
    private ContentTypeService contentTypeService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String list(ModelMap map) {
        map.put("contentTypeList",contentTypeService.findAll());
        return "/back/contentType/list";
    }
    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public String add(ModelMap map) {

        return "/back/contentType/add";
    }

    /**
     * 保存文章数据
     * @return
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public String save(@RequestParam("contentType")String contentType) {
        contentTypeService.save(contentType);
        return "ok";
    }

    /**
     * 保存文章数据
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public String delete(@RequestParam("id")Long id) {
        contentTypeService.delete(id);
        return "ok";
    }

}
